package cn.zongtilei;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TestServlet extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");// 这个是浏览器到服务器的乱码问题
		resp.setContentType("text/html;charset=utf-8");// 这个是服务器到浏览器
		ServletContext servletContext = getServletContext();
		Integer count = (Integer) servletContext.getAttribute("count");
		PrintWriter writer = resp.getWriter();
		writer.println("这是第" + count + "访问"); // 不借助jsp也可以在页面打印
		servletContext.setAttribute("count", count);
		System.out.println(count);
	}

}
